﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using NExt.Handler.Base.Default;
using System.Reflection;

namespace NExt.Handler.Base
{
    public class StaticHandlerFactory : IHttpHandlerFactory
    {
        private readonly IHttpHandler handler;

        public StaticHandlerFactory()
        {
            Type type = this.GetType();
            Assembly assembly = Assembly.GetAssembly(type);
            IReponseStreamBuilder embededResourceReponseStreamBuilder = new EmbeddedResourceResponseStreamBuilder(assembly);
            IReponseStreamBuilder externalFileReponseStreamBuilder = new ExternalFileReponseStreamBuilder(assembly);
            IReponseStreamBuilder chainedReponseStreamBuilder = new ChainedResponseStreamBuilder(embededResourceReponseStreamBuilder, externalFileReponseStreamBuilder);
            IResponseBuilder responseBuilder = new DefaultResponseBuilder(chainedReponseStreamBuilder);
            handler = new DefaultHandler(false, responseBuilder);
        }

        public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
        {
            return handler;
        }

        public void ReleaseHandler(IHttpHandler httpHandler)
        {
        }
    }
}
